#include "widget.h"
#include "ui_widget.h"

#include <QFont>
#include <QString>
#include <QIcon>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    this->setWindowTitle("我尊重老婆的选择！");
    on_pushButton_kiss_clicked();
    QIcon icon(":/1.jpg");
    this->setWindowIcon(icon);

    ui->pushButton_accept->setToolTip("接受");
    ui->pushButton_accept->setToolTipDuration(3000);

    ui->pushButton_reject->setToolTip("拒绝");
    ui->pushButton_reject->setToolTipDuration(3000);

    QFont font;
    font.setFamily("楷体");
    font.setStrikeOut(true);
    font.setPixelSize(8);
    ui->pushButton_reject->setFont(font);
}

Widget::~Widget()
{
    delete ui;
}



void Widget::on_pushButton_accept_clicked()
{
    ui->lineEdit->setText("好耶！！！最喜欢老婆了！！！");
    ui->label->setText("原文：老婆，你愿意和我做AI吗？");
    ui->pushButton_reject->setEnabled(0);
}


void Widget::on_pushButton_reject_clicked()
{
    int x1 = ui->pushButton_accept->geometry().x();
    int y1 = ui->pushButton_accept->geometry().y();
    int x2 = ui->pushButton_reject->geometry().x();
    int y2 = ui->pushButton_reject->geometry().y();

    ui->pushButton_reject->move(x1, y1);
    ui->pushButton_accept->move(x2, y2);

    // ui->label->setText("好耶！！！最喜欢老婆了！！！");
    // ui->pushButton_reject->setEnabled(0);
    on_pushButton_accept_clicked();
}


void Widget::on_pushButton_reject_pressed()
{
    // int width = this->geometry().width();
    // int height = this->geometry().height();

    // int x = rand() % (width - ui->pushButton_reject->geometry().width());
    // int y = rand() % (height - ui->pushButton_reject->geometry().height());

    // ui->pushButton_reject->move(x, y);
}

void Widget::on_pushButton_kiss_clicked()
{
    static QString str = " 老婆，你愿意和我做AI吗？";
    static int n = str.size();
    static int i = 0;
    if(i >= n) return;
    ui->lineEdit->setText(ui->lineEdit->text() + str[i++]);
    ui->label_num->setText("还剩" + QString::number(n - i) + "个字");
}

